// import Vue from 'vue';
import Clipboard from 'clipboard';

function clipboardSuccess() {
    // Vue.prototype.$message({message: '复制成功', type: 'success', duration: 1500,});
    console.log('复制成功')
}


function clipboardError() {
    // Vue.prototype.$message({message: '复制失败', type: 'error',});
    console.log('复制失败')
}

export function handleClipboard(text, event, onSuccess, onError) {
    event = event || {};
    const clipboard = new Clipboard(event.target, {text: () => text,});
    console.log('text', text)
    clipboard.on('success', () => {
        onSuccess ? onSuccess() : clipboardSuccess();
        clipboard.off('error');
        clipboard.off('success');
        clipboard.destroy();
        console.log('onSuccess', onSuccess)
        console.log('clipboardSuccess', clipboardSuccess)
    });
    clipboard.on('error', () => {
        onError ? onError() : clipboardError();
        clipboard.off('error');
        clipboard.off('success');
        clipboard.destroy();
    });
    clipboard.onClick(event);
}